﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_User : IUser
    {
        WishDayEntities _e;
        public D_User()
        {
            _e = new WishDayEntities();
        }
        public void Add(User obj)
        {
            _e.User.Add(obj);
            _e.SaveChanges();
        }

        public void Delete(int id)
        {
            var data = _e.User.Find(id);
            _e.User.Remove(data);
            _e.SaveChanges();
        }

        public User FindById(int id)
        {
            return _e.User.Find(id);
        }

        public List<User> GetAll()
        {
            return _e.User.ToList();
        }

        public void Update(int id, User obj)
        {
            var data = _e.User.Find(id);
            data.UserName = obj.UserName;
            data.PassWord = obj.PassWord;
            data.NickName = obj.NickName;
            data.HeadImg = obj.HeadImg;
            data.CreateTime = obj.CreateTime;
            data.Tel = obj.Tel;
            data.TokenID = obj.TokenID;
            data.Email = obj.Email;
            _e.SaveChanges();
        }
    }
}
